package cn.edu.xjtu.work.reverseVowels;

import java.util.HashSet;
import java.util.Set;

public class Solution {
  Set<Character> set = new HashSet<>();

  public Solution() {
    set.add('a');
    set.add('A');
    set.add('e');
    set.add('E');
    set.add('i');
    set.add('I');
    set.add('o');
    set.add('O');
    set.add('u');
    set.add('U');
  }

  /**
   * 哈希集合
   * 
   * @param s
   * @return
   */
  public String reverseVowels(String s) {

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      if (set.contains(s.charAt(i))) {
        sb.append(s.charAt(i));
      }
    }
    sb.reverse();
    int j = 0;
    StringBuilder ret = new StringBuilder();
    for (int i = 0; i < s.length(); i++) {
      if (set.contains(s.charAt(i))) {
        ret.append(sb.charAt(j++));
      } else {
        ret.append(s.charAt(i));
      }
    }
    return ret.toString();
  }

  /**
   * 双指针
   * 
   * @param s
   * @return
   */
  public String reverseVowels1(String s) {
    return null;
  }
}
